#!/bin/bash
source ~/.bash_profile

name=heartServer.jar

function start() { 
	stop
    nohup java  -jar heartServer.jar >/dev/null 2>&1 &
    echo "ok"
}  

function stop() { 
   ID=`ps -ef|grep "$name" |grep -v "$0" |grep -v "grep" |awk '{print $2}'`
   if [ -n "$ID" ];then
        kill $ID
        echo "Kill Old Run:"$ID
   fi
} 

function state() { 
	ps -ef|grep "$name"
} 

function restart() {  
    stop
    sleep 1
    start
} 

function state() {
   ps -ef|grep ${name}
}

case "$1" in
    start )  
        start  
        ;;  
    stop )  
        stop  
        ;;  
	state )  
        state  
        ;;  
    restart )  
        restart  
        ;;  
    * )  
        echo "no command,only start,stop,restart,state"  
        ;;  
esac 